package com.cndw.kongfu.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Connector {
	
	private Socket socket = null;
	
	private String host;
	
	private int port;
	
	private BufferedReader br = null;
	
	private PrintWriter pw = null;
	
	public Connector(String host, int port) {
		this.host = host;
		this.port = port;
	}
	
	public void connect() {
		
		try {
			if (socket == null) {
				socket = new Socket(host, port);
				br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				pw = new PrintWriter(socket.getOutputStream());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
		readData();
	}

	public void disconnect() {
		
		try {
			if (br != null) {
				br.close();
			}
			if (pw != null) {
				pw.close();
			}
			if (socket != null) {
				socket.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void readData() {
		while (true) {
			
		}
	}

}
